from autoframe.common.base import *


class AddressLocation(Base):

    def country(self, location, vlan):  # 国家 定位
        self.select_by_value((By.ID, location), vlan)

    def province(self, location, vlan):  # 省份 定位
        self.select_by_value((By.ID, location), vlan)

    def cities(self, location, vlan):  # 城市 定位
        self.select_by_value((By.ID, location), vlan)

    def districts(self, location, vlan):  # 城区 定位
        self.select_by_value((By.ID, location), vlan)

    def consignee(self, location, vlan):  # 收货人姓名
        self.send_keys((By.ID, location), vlan)

    def address(self, location, vlan):  # 详细地址 定位
        self.send_keys((By.ID, location), vlan)

    def tel(self, location, vlan):  # 电话  定位
        self.send_keys((By.ID, location), vlan)

    def email(self, location, vlan):  # 电子邮件地址 定位
        self.send_keys((By.ID, location), vlan)

    def zipcode(self, location, vlan):  # 邮政邮编 定位
        self.send_keys((By.ID, location), vlan)

    def mobile(self, location, vlan):  # 手机 定位
        self.send_keys((By.ID, location), vlan)

    def submit(self, location):  # 添加为收货地址按钮 定位
        self.click(location)

    def blue(self, location):  # 删除按钮 定位
        self.click(location)

    def ctrl_a(self, location):  # 全选 定位
        self.send_keys_class((By.ID, location), '全选')

    def font_text(self, location):  # 获取收货人姓名 定位
        return self.get_attribute_value((By.ID, location))

    '''
        操作方法
    '''

    def add_address(self):  # 添加地址
        self.country('selCountries_0', '中国')  # 国
        self.province('selProvinces_0', '江苏省')  # 省
        self.cities('selCities_0', '南京市')  # 市
        self.districts('selDistricts_0', '雨花台区')  # 区
        self.consignee('consignee_0', '李先生')  # 收货人姓名
        self.address('address_0', '江苏省南京市')  # 详细地址
        self.tel('tel_0', '123456789108')  # 电话
        self.email('email_0', '128246433@qq.com')  # 电子邮件
        self.zipcode('zipcode_0', '42323231')  # 邮编
        self.mobile('mobile_0', '123456789108')  # 手机
        self.submit(
            (By.XPATH, '/html/body/div[6]/div[2]/div/div/div/form/table/tbody/tr[5]/td[2]/input[1]'))  # 定位添加地址按钮

    def modify_address(self):  # 修改地址
        self.country('selCountries_0', '中国')  # 国
        self.province('selProvinces_0', '湖北省')  # 省
        self.cities('selCities_0', '武汉市')  # 市
        self.districts('selDistricts_0', '江汉区')  # 区
        self.ctrl_a('consignee_0')  # 全选
        self.consignee('consignee_0', '杨先生')  # 收货人姓名
        self.ctrl_a('address_0')  # 全选
        self.address('address_0', '湖北省武汉市江汉区')  # 详细地址
        self.ctrl_a('tel_0')  # 全选
        self.tel('tel_0', '13329755249')  # 电话
        self.ctrl_a('email_0')  # 全选
        self.email('email_0', 'yangruiwengmail@163.com')  # 电子邮件
        self.ctrl_a('zipcode_0')  # 全选
        self.zipcode('zipcode_0', '430021')  # 邮编
        self.ctrl_a('mobile_0')  # 全选
        self.mobile('mobile_0', '13329755249')  # 手机
        self.submit(
            (By.XPATH, '/html/body/div[6]/div[2]/div/div/div/form[1]/table/tbody/tr[5]/td[2]/input[1]'))  # 定位确认修改按钮

    def delete_address_cancel(self):  # 点击删除地址后     出现弹窗点击   取消
        self.blue((By.XPATH, '/html/body/div[6]/div[2]/div/div/div/form[1]/table/tbody/tr[5]/td[2]/input[2]'))
        self.alert_dismiss()  # 取消

    def delete_address_cancel_determine(self):  # 点击删除地址后     出现弹窗点击  确定
        self.blue((By.XPATH, '/html/body/div[6]/div[2]/div/div/div/form[1]/table/tbody/tr[5]/td[2]/input[2]'))
        self.alert_accept()  # 确定
